package com.xydtech.workflow.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.workflow.domain.WflFlowDocList;
import com.xydtech.workflow.service.IWflFlowDocListService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程影像资料库Controller
 *
 * @author JHON
 * @date 2022-01-04
 */
@Controller
@RequestMapping("/workflow/docList")
public class WflFlowDocListController extends BaseController {
    private String prefix = "workflow/docList";

    @Autowired
    private IWflFlowDocListService wflFlowDocListService;

    @RequiresPermissions("workflow:docList:view")
    @GetMapping()
    public String docList() {
        return prefix + "/docList";
    }


    /**
     * 查询流程影像资料库列表
     */
    @RequiresPermissions("workflow:docList:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WflFlowDocList wflFlowDocList) {
        startPage();
        List<WflFlowDocList> list = wflFlowDocListService.selectWflFlowDocListList(wflFlowDocList);
        return getDataTable(list);
    }

    /**
     * 导出流程影像资料库列表
     */
    @RequiresPermissions("workflow:docList:export")
    @Log(title = "流程影像资料库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WflFlowDocList wflFlowDocList) {
        List<WflFlowDocList> list = wflFlowDocListService.selectWflFlowDocListList(wflFlowDocList);
        ExcelUtil<WflFlowDocList> util = new ExcelUtil<WflFlowDocList>(WflFlowDocList.class);
        return util.exportExcel(list, "流程影像资料库数据");
    }

    /**
     * 新增流程影像资料库
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存流程影像资料库
     */
    @RequiresPermissions("workflow:docList:add")
    @Log(title = "流程影像资料库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WflFlowDocList wflFlowDocList) {
        return toAjax(wflFlowDocListService.insertWflFlowDocList(wflFlowDocList));
    }

    /**
     * 修改流程影像资料库
     */
    @GetMapping("/edit/{docId}")
    public String edit(@PathVariable("docId") Long docId, ModelMap mmap) {
        WflFlowDocList wflFlowDocList = wflFlowDocListService.selectWflFlowDocListByDocId(docId);
        mmap.put("wflFlowDocList", wflFlowDocList);
        return prefix + "/edit";
    }

    /**
     * 修改保存流程影像资料库
     */
    @RequiresPermissions("workflow:docList:edit")
    @Log(title = "流程影像资料库", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WflFlowDocList wflFlowDocList) {
        return toAjax(wflFlowDocListService.updateWflFlowDocList(wflFlowDocList));
    }

    /**
     * 删除流程影像资料库
     */
    @RequiresPermissions("workflow:docList:remove")
    @Log(title = "流程影像资料库", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(wflFlowDocListService.deleteWflFlowDocListByDocIds(ids));
    }
}
